﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="contact.aspx.cs" Inherits="UI.system.page.config.contact" %>
<%@ Import Namespace="Common" %>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title></title>
<script src="/js/jquery.min.js"></script>
<script src="/js/common.js"></script>
<script src="/js/md5.js"></script>
<script src="/js/swfupload.js"></script>
<script src="/system/js/admin.js"></script>
<script src="/system/layui/layui.js"></script>
<link rel="stylesheet" href="/system/layui/css/layui.css">
<link rel="stylesheet" href="/system/css/iframe.css">
<style>
  #container{
  width:100%;
  min-height:600px;
  }
  .layui-btn-normal{position:absolute; top: 0px; left:430px;}
</style>
</head>
<body>
<div style="margin: 35px; position:relative; padding-bottom:50px;">
	<form class="layui-form" style="padding-left:0px;">
        <div class="layui-form-item">
			<label class="layui-form-label">公司名称</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="comname" placeholder="请输入公司名称" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.ComName%>">
                
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">联系人</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="contactname" placeholder="请输入联系人姓名" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.ContactName%>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">固定电话</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="phone" placeholder="请输入固定电话" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Phone%>">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">手机号码</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="mobile" placeholder="请输入手机号码" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Mobile%>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">QQ号码</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="qq" placeholder="请输入QQ号码" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.QQ%>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">微信号</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="weixin" placeholder="请输入微信号" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.WeiXin%>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">新浪微博</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="sina" placeholder="请输入新浪微博" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Sina%>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">电子邮箱</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="email" placeholder="请输入电子邮箱" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Email%>">
			</div>
		</div>
        <div class="layui-form-item">
			<label class="layui-form-label">公司地址</label>
			<div class="layui-input-block" style="width:300px;">
				<input id="address" placeholder="请输入公司地址" lay-verify="required" autocomplete="off" class="layui-input" value="<%=info.Address%>" lat="<%=info.Lat %>" lng="<%=info.Lng %>" city="">
                <a lay-filter="save" class="layui-btn layui-btn-normal" style="left:320px;" onclick="Search()"> 搜&nbsp;&nbsp;索 </a>
			</div>
		</div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
			<div class="layui-input-block">
				<div id="container"></div>
			</div>
        </div>
	</form>
    <a lay-filter="save" class="layui-btn layui-btn-normal" onclick="Update_Contact()"> &nbsp;&nbsp;保&nbsp;&nbsp;&nbsp;&nbsp;存&nbsp;&nbsp; </a>
</div>
<script>
    function Update_Contact() {
        var data = {};
        data.act = "Update_Contact";
        data.comname = $("#comname").val();
        data.contactname = $("#contactname").val();
        data.phone = $("#phone").val();
        data.mobile = $("#mobile").val();
        data.qq = $("#qq").val();
        data.weixin = $("#weixin").val();
        data.sina = $("#sina").val();
        data.email = $("#email").val();
        data.lat =  $("#address").attr("lat");
        data.lng =  $("#address").attr("lng");
        data.address = $("#address").val();
        if (data.comname.indexOf("&") > -1) {
            LayerBox.Error("公司名称里不能包含&字符");
            return;
        }
        if (data.contactname.indexOf("&") > -1) {
            LayerBox.Error("联系人里不能包含&字符");
            return;
        }
        if (data.phone.indexOf("&") > -1) {
            LayerBox.Error("固定电话里不能包含&字符");
            return;
        }
        if (data.mobile.indexOf("&") > -1) {
            LayerBox.Error("手机号码里不能包含&字符");
            return;
        }
        if (data.qq.indexOf("&") > -1) {
            LayerBox.Error("QQ号码里不能包含&字符");
            return;
        }
        if (data.weixin.indexOf("&") > -1) {
            LayerBox.Error("微信号里不能包含&字符");
            return;
        }
        if (data.sina.indexOf("&") > -1) {
            LayerBox.Error("新浪微博里不能包含&字符");
            return;
        }
        if (data.email.indexOf("&") > -1) {
            LayerBox.Error("电子邮箱里不能包含&字符");
            return;
        }
        if (data.address.indexOf("&") > -1) {
            LayerBox.Error("公司地址里不能包含&字符");
            return;
        }
        if (data.lat == "0" && data.lng=="0") {
            LayerBox.Error("请在地图上选择公司位置");
            return;
        }
        data.sign = GetSign(data.act);
        LayerBox.Loading();
        Ajax.Post("/tools/Admin.ashx", data, function (r) {
            LayerBox.Close.ByAll();
            var json = $.parseJSON(r);
            if (json.state) {
                LayerBox.Success("保存成功");
            }
            else {
                LayerBox.Error(json.msg);
            }
        });
    };
</script>

<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
<script>
    var lat=<%=info.Lat %>;
    var lng=<%=info.Lng %>;
    var searchService,citylocation, map, marker;
    var init = function () {
        if(lat==0 && lng==0){
            //获取城市列表接口设置中心点

            map = new qq.maps.Map(document.getElementById('container'), {

                zoom: 18
            });
            citylocation = new qq.maps.CityService({
                complete: function (result) {
                    map.setCenter(result.detail.latLng);
                    $("#address").attr("city",result.detail.name);
                    marker=new qq.maps.Marker({
                        position:result.detail.latLng, 
                        map:map
                    }); 
                }
            });
            //调用searchLocalCity();方法    根据用户IP查询城市信息。
            citylocation.searchLocalCity();

        }else{
            var center = new qq.maps.LatLng(lat, lng);
            map = new qq.maps.Map(document.getElementById('container'), {
                center: center,
                zoom: 18
            });
            var pos = new qq.maps.LatLng(lat,lng);
            marker=new qq.maps.Marker({
                        position:pos, 
                        map:map
            }); 

            citylocation = new qq.maps.CityService({
                complete: function (result) {
                    $("#address").attr("city",result.detail.name);
                }
            });
            //调用searchLocalCity();方法    根据用户IP查询城市信息。
            citylocation.searchLocalCity();
        }

        
            qq.maps.event.addListener(map, 'click', function(event) {
                
                if(marker2!=null){
                marker2.setMap(null);
                }
                if(marker!=null){
                marker.setMap(null);     
                } 
                marker=new qq.maps.Marker({
                        position:event.latLng, 
                        map:map
                });    
                $("#address").attr("lat",event.latLng.lat).attr("lng",event.latLng.lng);
            });
            
    }


    var latlngBounds = new qq.maps.LatLngBounds();
    var marker2;
    //调用Poi检索类
    searchService = new qq.maps.SearchService({
        complete : function(results){
            try{
                var len=results.detail.pois.length;
            }catch(e){
                LayerBox.Error("没有检索到您要找的位置");
                return;
            }

            if(marker2!=null){
                marker2.setMap(null);
            }
            if(marker!=null){
                marker.setMap(null);     
            }
            
            var pois = results.detail.pois;
            for(var i = 0,l = pois.length;i < l; i++){
                
                var poi = pois[i];
                latlngBounds.extend(poi.latLng);  
                marker2 = new qq.maps.Marker({
                    map:map,
                    position: poi.latLng
                });
                $("#address").attr("lat",poi.latLng.lat).attr("lng",poi.latLng.lng);
                map.zoomTo(18);
                map.setCenter(poi.latLng);
                break;

            }
            map.fitBounds(latlngBounds);
            
        },
        error: function() {
            LayerBox.Error("没有检索到您要找的位置");
        }
    });


    function Search() {
        
        searchService.setLocation($("#address").attr("city"));
        searchService.search($("#address").val());
    }
    init();
</script>
</body>
</html>